var app = getApp()
var dialUtil = require("../../utils/dialUtil.js")
var util = require("../../utils/util.js")
var settingModel = require('../../model/settingModel.js')
var wxParse = require('../../plugins/wxParse/wxParse.js');
Page({
  data: {
    shopInfo: null,
    urls:[],
    tags:['环境图片','门店简介'],
    tagIndex:0,
    fold: true,//门店简介折叠
  },
  onLoad: function(options) {
    this.init()

  },
  switchTag(e) {
    this.setData({
      tagIndex: e.currentTarget.id
    })
  },
  init() {
    var that = this
    util.showLoading("加载中")
    settingModel.getStore(res => {
      wx.hideLoading()
      if (res.status == 1) {
        util.failToast(res.msg)
        return
      }
      if (res.data.html) wxParse.wxParse('info', 'html', res.data.html, that, 5);
      that.setData({
        shopInfo: res.data
      })
    })
    settingModel.getShopImgList(res=>{
      if (res.status == 1) {
        util.failToast(res.msg)
        return
      }
      that.setData({
        urls:res.data
      })
    })
  },
  //门店简介折叠开关
  bindFold(){
    this.setData({
      fold:!this.data.fold
    })
  },
  openCallPhone(e) {
    dialUtil.dial(this.data.shopInfo.phone)
  },
  bindShowImg(e) {
    var position=parseInt(e.currentTarget.id)
    var urls=this.data.urls
    wx.previewImage({
      current: urls[position], // 当前显示图片的https链接
      urls: urls // 需要预览的图片https链接列表
    })
  },
  bindOpenLocation(){
    wx.openLocation({
      latitude:this.data.shopInfo.lat,
      longitude:this.data.shopInfo.lng,
      scale: 18,
      name:this.data.shopInfo.name,
      address:this.data.shopInfo.address+this.data.shopInfo.addressInfo
    })
  },
  navToImg(){
    app.data.shopImgs = this.data.urls
    wx.navigateTo({
      url: '../shop_info_image/shop_info_image',
    })
  }
})